﻿#if DEBUG
    #define USE_DEBUG_MODE
#else
    #define USE_RELEASE_MODE
#endif 

using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;

namespace Why.Common
{
    public sealed class Checker
    {
        #region 静态变量
        private const string NOT_NULL_FAILING_MESSAGE = "{0}不能为NULL";
        private const string NOT_NULL_OR_EMPTY_FAILING_MESSAGE = "{0}不能为NULL或空值";
        private const string IS_ASSIGNABLE_TO_FAILING_MESSAGE = "{0}{1}";

        #endregion

        #region 接口
        /// <summary>
        /// 通用检查器接口
        /// </summary>
        public interface IChecker
        {
            /// <summary>
            /// 检查参数是否通过
            /// </summary>
            /// <param name="obj">检查参数</param>
            /// <returns>通过返回true, 反之为false</returns>
            bool Pass(object obj);
            /// <summary>
            /// 当检查错误时返回错误消息
            /// </summary>
            /// <param name="objName">错误参数名</param>
            /// <returns>错误消息</returns>
            string GetErrorMessage(string objName);
        }
        #endregion

        #region 内部类

        private sealed class NotNullChecker : IChecker
        {
            public bool Pass(object obj)
            {
                return obj != null;
            }

            public string GetErrorMessage(string objName)
            {

            }
        }

        private sealed class NetNullOrEmptyChecker : IChecker
        {
            #region IChecker Members

            public bool Pass(object obj)
            {
                throw new NotImplementedException();
            }

            public string GetErrorMessage(string objName)
            {
                throw new NotImplementedException();
            }

            #endregion
        }

        private sealed class IsAssignableToChecker<TargetType> : IChecker
        {
            #region IChecker Members

            public bool Pass(object obj)
            {
                throw new NotImplementedException();
            }

            public string GetErrorMessage(string objName)
            {
                throw new NotImplementedException();
            }

            #endregion
        }

        private sealed class GreaterThanChecker<T> : IChecker
        {
            #region IChecker Members

            public bool Pass(object obj)
            {
                throw new NotImplementedException();
            }

            public string GetErrorMessage(string objName)
            {
                throw new NotImplementedException();
            }

            #endregion
        }

        private sealed class GreaterThanOrEqualChecker<T> : IChecker
        {
            #region IChecker Members

            public bool Pass(object obj)
            {
                throw new NotImplementedException();
            }

            public string GetErrorMessage(string objName)
            {
                throw new NotImplementedException();
            }

            #endregion
        }

        private sealed class LessThanChecker<T> : IChecker
        {
            #region IChecker Members

            public bool Pass(object obj)
            {
                throw new NotImplementedException();
            }

            public string GetErrorMessage(string objName)
            {
                throw new NotImplementedException();
            }

            #endregion
        }

        private sealed class LessThanOrEqualChecker<T> : IChecker
        {
            #region IChecker Members

            public bool Pass(object obj)
            {
                throw new NotImplementedException();
            }

            public string GetErrorMessage(string objName)
            {
                throw new NotImplementedException();
            }

            #endregion
        }

        #endregion

        #region 检查方法
        #endregion

    }


    [Serializable]
    public abstract class DesignByContractException : ApplicationException
    {
        protected DesignByContractException() { }
        protected DesignByContractException(string message) { }
        protected DesignByContractException(string message, Exception inner) { }
    }

    [Serializable]
    public sealed class PreconditionException : DesignByContractException
    {
        public PreconditionException() : base() { }
        public PreconditionException(string message) : base(message) { }
        public PreconditionException(string message, Exception inner) : base(message, inner) { }
    }

    [Serializable]
    public sealed class PostconditionException : DesignByContractException
    {
        public PostconditionException() : base() { }
        public PostconditionException(string message) : base(message) { }
        public PostconditionException(string message, Exception inner) : base(message, inner) { }
    }

    [Serializable]
    public sealed class InvariantException : DesignByContractException
    {
        public InvariantException() : base() { }
        public InvariantException(string message) : base(message) { }
        public InvariantException(string message, Exception inner) : base(message, inner) { }
    }

    [Serializable]
    public sealed class AssertionException : DesignByContractException
    {
        public AssertionException() : base() { }
        public AssertionException(string message) : base(message) { }
        public AssertionException(string message, Exception inner) : base(message, inner) { }
    }
}
